package com.sky.controller.admin;


import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@Slf4j
@Api(tags = "店铺端 查询 设置营业状态")
@RequestMapping("/admin/shop")
public class ShopController {

    @Autowired
    RedisTemplate redisTemplate;
    public static final String KEY = "SHOP_STATUS";

    @ApiOperation(value = "店铺端 查询营业状态")
    @GetMapping("/status")
    public Result<Integer> getshopstatus(){

        log.info("查询店铺状态");
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer status = (Integer) valueOperations.get(KEY);

        return Result.success(status);
    }

    @ApiOperation(value = "设置店铺的营业状态 ")
    @PutMapping("/{status}")
    public Result setstatus(@PathVariable Integer status){

        log.info("设置店铺状态：{}", status);


        ValueOperations valueOperations = redisTemplate.opsForValue();

        valueOperations.set(KEY,status);

        return Result.success();

    }

}
